package com.jyq.jsp.servlet;

import com.jyq.jsp.utils.ServletUtils;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.io.PrintWriter;
import java.util.Enumeration;
import java.util.zip.GZIPOutputStream;

/**
 * @author Jiang Yongqiang
 */
@WebServlet(name = "HeadServlet",urlPatterns = "/head.html")
public class HeadServlet extends HttpServlet {
    protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {

    }

    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {

        Enumeration<String> headerNames = request.getHeaderNames();
        StringBuilder stringBuilder = new StringBuilder();
        request.getSession();
        while (headerNames.hasMoreElements()){
            String headerName = headerNames.nextElement();
            stringBuilder.append("<br/>").append(headerName).append(":");
            String header = request.getHeader(headerName);
            stringBuilder.append("<br/>").append(header);
        }
        //自动刷新
        ServletUtils.setAttribute(request,"head",stringBuilder.toString());
        ServletUtils.forward(request,response,"/jsp/head.jsp");
    }
}
